package net.ojbk.util;

import java.util.Random;

/**
 * public static String getRandomString(int n) { // 根据随机字符字典 获取 n长 随机字符串
 * public static String getRandomString() { // 根据随机字符字典 获取 6位长 随机字符串 
 * 
 * @author twobox
 *
 */
public class StringTool {
	public static final char[] CHARS = {'2','3','4','5','6','7','8','9',
			'A','B','C','D','E','F','G','H','J','K','L','M','N',
			'P','Q','R','S','T','U','V','W','X','Y','Z'};// 随机字符字典
	
	public static Random random = new Random();

	public static String getRandomString(int n) { // 根据随机字符字典 获取 n长 随机字符串
		StringBuffer buffer = new StringBuffer();
		for (int i=0; i<n; i++) {
			buffer.append(CHARS[random.nextInt(CHARS.length)]);
		}
		return buffer.toString();
	}
	public static String getRandomString() { // 根据随机字符字典 获取 6位长 随机字符串 
		return getRandomString(6);
	}
	
	public static String getRandomNumberString(int n) {
		char[] newId = new char[n]; // 存新ID
		newId[0] = (char)(int)('0' + 1 + Math.random()*9);
		for (int i=1; i<n; i++) {
			newId[i] = (char)(int)('0' + Math.random()*10);
		}
		return new String(newId);
	}
	public static String getRandomNumberString() {
		return getRandomNumberString(5);
	}
	
}
